<?php
namespace Admin\Controller;

use Common\Controller\AdminBaseController;
use \Common\Lib\Util\File as FileUtil;

class IndexController  extends AdminBaseController
{
    public function index() {
        $this->display();
    }

    public function main() {

        $info = array(
            '程序版本'=> WEB_VERSION,
            '运行环境' => $_SERVER['SERVER_SOFTWARE'],
            'PHP版本' => PHP_VERSION,
            'PHP运行方式' => php_sapi_name(),
            '数据库' => C('DB_TYPE').' '.$this->_get_mysql_version(),
            'ThinkPHP版本' => THINK_VERSION,
            '上传附件限制' => ini_get('upload_max_filesize'),
            '执行时间限制' => ini_get('max_execution_time') . "s",
            '剩余空间'   => round((@disk_free_space(".") / (1024 * 1024)), 2) . 'M',
        );

        $this->assign('info',$info);
        $this->display();
    }

    // 设置皮肤(颜色)
    public function setSkin() {
        $skin = I('post.skin');
        $data =  array(
            'admin_id' => $this->_admin['admin_id'],
            'skin'     => $skin,
        );
        if(D('Admin')->save($data) !== false)
            session('admin.skin',$skin);
    }

    //数据库版本
    private function _get_mysql_version() {
        $mysql = M()->query("select VERSION() as version");
        return $mysql[0]['version'];
    }

    // 清除缓存操作
    public function cache() {
        FileUtil::del_dir(TEMP_PATH);
        FileUtil::del_dir(CACHE_PATH);
        FileUtil::del_dir(DATA_PATH);
        file_exists($file = RUNTIME_PATH . 'common~runtime.php') && @unlink($file);
        $this->success('更新缓存成功！', U('Index/main'));
    }
}